<template>
  <div class="login-container">
    <!-- 登录卡片 -->
    <div class="login-card">
      <!-- 左侧插画区 -->
      <div class="illustration-section">
        <div class="decorative-circle"></div>
        <img
            src="/imgs/login/svg/login.svg"
            alt="安全登录"
            class="login-illustration"
        >
        <div class="branding">
          <h2>企业人事管理系统</h2>
          <p>Professional HR Management</p>
        </div>
      </div>

      <!-- 右侧表单区 -->
      <div class="form-section">
        <div class="form-header">
          <h3>账号登录</h3>
          <p>使用企业邮箱登录系统</p>
        </div>

        <el-form
            :model="loginForm"
            @submit.native.prevent="handleLogin"
            class="login-form"
        >
          <div class="form-group">
            <label>电子邮箱</label>
            <el-input
                v-model="loginForm.email"
                placeholder="boss@company.com"
                prefix-icon="el-icon-message"
                class="custom-input"
            />
          </div>

          <div class="form-group">
            <label>登录密码</label>
            <el-input
                v-model="loginForm.password"
                type="password"
                placeholder="123456"
                show-password
                prefix-icon="el-icon-lock"
                class="custom-input"
            />
          </div>

          <el-button
              native-type="submit"
              class="submit-btn"
              :loading="loading"
          >
            立即登录
          </el-button>
          <div class="helper-links">
<!--            <el-link type="info">注册账号</el-link>-->
            <el-link type="info">忘记密码?</el-link>
          </div>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import qs from "qs";
import axios from "axios";
import {Message} from "element-ui";

export default {
  data() {
    return {
      loginForm: {
        email: '',
        password: ''
      },
      loading: false
    }
  },
  methods: {
    handleLogin() {
      if (!this.validateForm()) return

      this.loading = true
      let data = qs.stringify(this.loginForm);
      console.log(data);
      axios.post(this.$BASE_URL + '/v1/user/login', data)
          .then((response) => {
            console.log(response.data)
            if (response.data.state === 2000) {
              localStorage.setItem('user', JSON.stringify(response.data.data));
              window.location.href = '/';
            } else {
              Message.error(response.data.message);
            }
            this.loading = false;
          });
    },
    validateForm() {
      if (!this.loginForm.email) {
        Message.warning('请输入邮箱地址')
        return false
      }
      if (!this.loginForm.password) {
        Message.warning('请输入登录密码')
        return false
      }
      return true
    }
  }
}
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f0f4ff 0%, #e6f0ff 100%);
}

.login-card {
  width: 900px;
  height: 560px;
  background: #ffffff;
  border-radius: 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
  display: flex;
  position: relative;
  overflow: hidden;
}

/* 左侧插画区 */
.illustration-section {
  flex: 1;
  background: linear-gradient(135deg, #7b9cff 0%, #668cff 100%);
  padding: 40px;
  position: relative;
}

.decorative-circle {
  position: absolute;
  top: -60px;
  right: -60px;
  width: 200px;
  height: 200px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50%;
}

.login-illustration {
  width: 100%;
  //max-width: 280px;
  margin: 60px auto 0;
  //display: block;
}

.branding {
  position: absolute;
  bottom: 40px;
  left: 40px;
  color: white;
}

.branding h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.branding p {
  font-size: 14px;
  opacity: 0.9;
}

/* 右侧表单区 */
.form-section {
  flex: 1;
  padding: 60px 40px;
}

.form-header {
  text-align: center;
  margin-bottom: 40px;
}

.form-header h3 {
  font-size: 22px;
  color: #1a1a1a;
  margin-bottom: 8px;
}

.form-header p {
  color: #666;
  font-size: 14px;
}

.login-form {
  max-width: 320px;
  margin: 0 auto;
}

.form-group {
  margin-bottom: 24px;
}

.form-group label {
  display: block;
  color: #444;
  font-size: 13px;
  margin-bottom: 8px;
}

.custom-input {
  border-radius: 12px;
}

.submit-btn {
  width: 100%;
  height: 48px;
  background: linear-gradient(135deg, #7b9cff 0%, #668cff 100%);
  border: none;
  border-radius: 12px;
  color: white;
  font-size: 14px;
  margin-top: 20px;
  transition: transform 0.2s;
}

.submit-btn:hover {
  transform: translateY(-2px);
}

.helper-links {
  margin-top: 24px;
  display: flex;
  justify-content: space-between;
}
</style>
<!--<script>-->
<!--import axios from "axios";-->
<!--import qs from "qs";-->
<!--import { Message } from 'element-ui';-->

<!--export default {-->
<!--  data() {-->
<!--    return {-->
<!--      user: {-->
<!--        email: '',-->
<!--        password: ''-->
<!--      }-->
<!--    };-->
<!--  },-->
<!--  methods: {-->
<!--    login(){-->
<!--      let data = qs.stringify(this.user);-->
<!--      console.log(data);-->
<!--      axios.post(this.$BASE_URL + '/v1/users/login', data)-->
<!--          .then((response) => {-->
<!--            if (response.data.state === 2000) {-->
<!--              // 登录成功-->
<!--              // 将用户信息保存到 localStorage 中-->
<!--              localStorage.setItem('users', JSON.stringify(response.data.data));-->
<!--              // 跳转到首页-->
<!--              window.location.href = '/';-->
<!--            } else {-->
<!--              // 登录失败-->
<!--              Message.error(response.data.message);-->
<!--            }-->
<!--          });-->
<!--    }-->
<!--  }-->
<!--};-->
